package com.ymatou.iapi.godmch.testcase;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getServiceRelationBean;
import com.ymatou.iapi.godmch.service.getServiceRelationCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.serviceRelation;
import com.ymttest.database.sqlwapper.godmch.serviceRelationWapper;
/**
*服务关系查询
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getServiceRelation{
	private static getServiceRelationBean bean;
	private static getServiceRelationCall call;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("服务关系查询");
	}

	@Before
	public void caseUp() {
		bean=new getServiceRelationBean();
		call=new getServiceRelationCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws InterruptedException, JSONException
	{
		serviceRelationWapper serviceRelationWapper=new serviceRelationWapper();
		serviceRelation relation=serviceRelationWapper.selectByPrimaryKey(bean.getProviderId(), bean.getMchId(), bean.getServiceType());
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
		if(relation!=null && relation.getMchId()!=null && relation.getMchId()!=0)
		   Logger.verifyEquals(true, call.getHasRelation(), "验证HasRelation");
	    else
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_001() {
		Logger.start(true,"正例-服务关系查询-服务商没有服务国家");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(mchBean);
			
			bean.setProviderId(providerId);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_001_1() {
		Logger.start(true,"正例-服务关系查询-有服务国家");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);
			
			bean.setProviderId(providerId);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_002() {
		Logger.start(true,"反例-服务关系查询-服务商服务国家 与 商户国家不一致");
		try {

			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("DEU");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);
			
			bean.setProviderId(providerId);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_003() {
		Logger.start(true,"反例-服务关系查询-服务商与商户没有出口退税服务关系");
		try {
			
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),2);//1出口退税 2其他
			
			bean.setProviderId(providerId);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			//Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_004() {
		Logger.start(true,"反例-服务关系查询-服务商id不存在");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);//1出口退税 2其他
			
			bean.setProviderId(providerId+1);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_005() {
		Logger.start(true,"反例-服务关系查询-服务商id为空");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);//1出口退税 2其他
			
			//bean.setProviderId(providerId+1);
			bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_006() {
		Logger.start(true,"反例-服务关系查询-商户id不存在");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);//1出口退税 2其他
			
			bean.setProviderId(providerId);
			bean.setMchId(mchBean.getMchId()+1);
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getServiceRelation_007() {
		Logger.start(true,"反例-服务关系查询-商户id为空");
		try {
			//服务商
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			//渠道
			createmchBean mchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			mchBean.setCountry("CAN");
			GodmchManageCallService.createmchCallForChannel(mchBean);
			//添加服务关系
			GodmchManageCallService.InitAddServiceRelation(providerId,mchBean.getMchId(),1);//1出口退税 2其他
			
			bean.setProviderId(providerId);
		//	bean.setMchId(mchBean.getMchId());
			bean.setServiceType(1);

			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
			Logger.verifyEquals(false, call.getHasRelation(), "验证HasRelation");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}